package com.wallet.common.vo;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;

public class PageResult<T> implements Serializable {

    private static final long serialVersionUID = 7907499684048847072L;

    public PageResult(){}
    private Boolean hasNextPage;
    private List<T> list;

    /**
     * 当前页码
     */
    private Integer pageNum;

    /**
     * 总页数
     */
    private Integer pages;
    /**
     * 总记录数
     *
     */
    private Long totalCount;

    /**
     * 将PageHelper插件中的Page转换成自定义的分页结果
     * @param page
     * @return
     */
    public static <T> PageResult getPageResult(PageInfo<T> page){
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setList(page.getList());
        pageResult.setPageNum(page.getPageNum());
        pageResult.setTotalCount(page.getTotal());
        pageResult.setPages(page.getPages());
        pageResult.setHasNextPage(page.getPageNum() < page.getPages() ?  true : false);
        return pageResult;
    }

    public static <T> PageResult getPageResult(Page<T> page){
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setList(page.getResult());
        pageResult.setPageNum(page.getPageNum());
        pageResult.setTotalCount(page.getTotal());
        pageResult.setPages(page.getPages());
        pageResult.setHasNextPage(page.getPageNum() < page.getPages() ?  true : false);
        return pageResult;
    }

    /**
     * 将PageHelper插件中的Page转换成自定义的分页结果
     * @param list
     * @param pageNum
     * @param totalCount
     * @param pages
     * @param <T>
     * @return
     */
    public static <T> PageResult getPageResult(List<T> list, int pageNum, long totalCount, int pages){
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setList(list);
        pageResult.setPageNum(pageNum);
        pageResult.setTotalCount(totalCount);
        pageResult.setPages(pages);
        pageResult.setHasNextPage(pageNum < pages ?  true : false);
        return pageResult;
    }

    public Boolean getHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(Boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getPage() {
        return pageNum;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }


    public Integer getPages() {
        return pages;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }


}

